package com.example.dragon.xmf;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/6/25/025.
 */

public class UserWebActivity extends AppCompatActivity implements View.OnClickListener{
    LinearLayout backLayout;
    WebView userweb;
    TextView titleTV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("zwttt","loadsctivity");
        setContentView(R.layout.userweb_layout);
        initView();
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        Log.i("zwttt",url);
        String title = intent.getStringExtra("title");
        setTitle(title);
        setWebUrl(url);
    }

    private void initView() {
        backLayout = (LinearLayout) findViewById(R.id.backLayout);
        backLayout.setOnClickListener(this);
        userweb = (WebView) findViewById(R.id.userweb);
        titleTV = (TextView) findViewById(R.id.titleTV);
    }

    private void setWebUrl(String url) {
        userweb.loadUrl(url);
    }
    private void setTitle(String title){
        titleTV.setText(title);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //返回按钮
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            if(userweb.canGoBack()){
                userweb.goBack();
            }else{
                finish();
            }
        }
        return false;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.backLayout:
                onKeyDown(KeyEvent.KEYCODE_BACK,null);
                break;
        }
    }
}
